<?php 
 include_once dirname(__FILE__)."/config.php";
 class parametre_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_param;
		 protected $_nom_param;
		 protected $_type_param;
		 protected $_contraint_param;
		 protected $_labell;
		 protected $_valeur_param;
		 protected $_valeur_extension;
		 public function get_name_table(){ return "parametre";}
		 public function get_name_code_param(){ return "code_param";}
		 public function get_name_nom_param(){ return "nom_param";}
		 public function get_name_type_param(){ return "type_param";}
		 public function get_name_contraint_param(){ return "contraint_param";}
		 public function get_name_labell(){ return "labell";}
		 public function get_name_valeur_param(){ return "valeur_param";}
		 public function get_name_valeur_extension(){ return "valeur_extension";}
		 public function set_code_param($parametre){  $this->_code_param=$parametre;}	
		 public function set_nom_param($parametre){  $this->_nom_param=$parametre;}	
		 public function set_type_param($parametre){  $this->_type_param=$parametre;}	
		 public function set_contraint_param($parametre){  $this->_contraint_param=$parametre;}	
		 public function set_labell($parametre){  $this->_labell=$parametre;}	
		 public function set_valeur_param($parametre){  $this->_valeur_param=$parametre;}	
		 public function set_valeur_extension($parametre){  $this->_valeur_extension=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_param(){ return $this->_code_param;}
		 public function get_nom_param(){ return $this->_nom_param;}
		 public function get_type_param(){ return $this->_type_param;}
		 public function get_contraint_param(){ return $this->_contraint_param;}
		 public function get_labell(){ return $this->_labell;}
		 public function get_valeur_param(){ return $this->_valeur_param;}
		 public function get_valeur_extension(){ return $this->_valeur_extension;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 parametre(
			nom_param,
			type_param,
			contraint_param,
			labell,
			valeur_param,
			valeur_extension)
 VALUES(
			'".$this->_nom_param."',
			'".$this->_type_param."',
			'".$this->_contraint_param."',
			'".$this->_labell."',
			'".$this->_valeur_param."',
			'".$this->_valeur_extension."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_nom_param)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
nom_param='".$this->_nom_param."'";
}
if(!empty($this->_type_param)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
type_param='".$this->_type_param."'";
}
if(!empty($this->_contraint_param)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
contraint_param='".$this->_contraint_param."'";
}
if(!empty($this->_labell)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
labell='".$this->_labell."'";
}
if(!empty($this->_valeur_param)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
valeur_param='".$this->_valeur_param."'";
}
if(!empty($this->_valeur_extension)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
valeur_extension='".$this->_valeur_extension."'";
}
$sql="UPDATE 
parametre SET 
 ".$sql."
								WHERE code_param ='".$this->_code_param."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
parametre 
 
									WHERE code_param ='".$this->_code_param."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
parametre ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_param,
		nom_param,
		type_param,
		contraint_param,
		labell,
		valeur_param,
		valeur_extension
 FROM 
 parametre";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_param=$row->code_param;
		$this->_nom_param=$row->nom_param;
		$this->_type_param=$row->type_param;
		$this->_contraint_param=$row->contraint_param;
		$this->_labell=$row->labell;
		$this->_valeur_param=$row->valeur_param;
		$this->_valeur_extension=$row->valeur_extension;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>